#include <QtCore/QCoreApplication>
#include <QRegExp>
#include "helper.h"
#include "mainloop.h"

int main(int argc, char *argv[])
{
    QCoreApplication::setOrganizationName("IpseSoft");
    QCoreApplication::setOrganizationDomain("ipse.ru");
    QCoreApplication::setApplicationName("Kotik");
    QCoreApplication a(argc, argv);

    Helper *helper = new Helper();
    MainLoop *mainloop = new MainLoop();

    QRegExp helpValidator("-{1,2}h(elp)?$", Qt::CaseInsensitive);

    if (argc > 1)
    {
        for (int i = 1; i < argc; ++i)
        {
            QString param(argv[i]);
            if (helpValidator.exactMatch(param))
            {
                helper->showUsage();
                return EXIT_SUCCESS;
            }
            else if (param == "-v" || param == "--version")
            {
                helper->showVersion();
                return EXIT_SUCCESS;
            }
            else if ( param == "-c" )
            {
                mainloop->createAccount();
                return EXIT_SUCCESS;
            }
            else
            {
                helper->wrongParametr(argv[0], param);
                return EXIT_FAILURE;
            }
        }
    }

    return a.exec();
}
